﻿var express=require("express");
var app=express();
var fs=require("fs");

app.get('/listUsers',function(req,resp){
	fs.readFile(__dirname+"/"+"users.json",'utf8',function(err,data){
		console.log(data);
		resp.end(data);
	});
})

//添加新用户
var user={
	"user4":{
		"name":"jack",
		"password":"123456",
		"profession":"teacher",
		"id":4
	}
}

app.get('/addUser',function(req,resp){
	//读取已存在的数据
	fs.readFile(__dirname+"/"+"users.json",'utf8',function(err,data){
		console.log(data);
		data=JSON.parse(data.trim());
		data["user4"]=user["user4"];
		console.log(data);
		resp.end(JSON.stringify(data));
	});
})

var server=app.listen(8082,function(){
	console.log("server running at 127.0.0.1:8082");
})